package com.dongdongshop.controller;

import com.aliyuncs.exceptions.ClientException;
import com.dongdongshop.service.SmsService;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

    /*
     * 前台页面注册：发送短信验证码
     * 1.验证吗：随机数
     * 2.手机号
     * */
    @RequestMapping("send")
    @ResponseBody
    public String send(String phoneNum) throws ClientException {

        //随机生产4位，6伪，8位验证码
        //使用阿帕奇工具包里jar包里的方法
        String code = RandomStringUtils.randomNumeric(6);//随机获取纯数字的验证码
        smsService.sendSms(phoneNum,code);
        return "ok";
    }

    //
    public static void main(String[] args) {
        //阿帕奇工具包里jar包里的方法
        String phoneNum="  ";
        //自定义，你说设密码空就什么空
        if (phoneNum == null || phoneNum.equals("")){
            System.out.println(">>>>>phoneNum为空");
        }
        //null ，""," ", "   " 都可以时空
        if (StringUtils.isBlank(phoneNum)){//判断是空
            System.out.println("----------phoneNum为空");
        }
        if (StringUtils.isEmpty(phoneNum)){//判断是空
            System.out.println("+++++++++++phoneNum为空");
        }

    }
}

